<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:a="attribute"
    xmlns:o="object"
    xmlns:c="collection"
>

  <xsl:output method="text" indent="yes" encoding="utf-8" version="1.0"/>


  <xsl:template match="/" >
    <xsl:for-each select="//c:Entities">
      <xsl:call-template name="Entitie"></xsl:call-template>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="Entitie">
    <xsl:for-each select="o:Entity">
      <xsl:if test="count(a:Comment)>0">
/**
 * <xsl:value-of select="a:Comment"></xsl:value-of>
 */
</xsl:if>class <xsl:value-of select="a:Name"/>{<xsl:for-each select="c:Attributes/o:EntityAttribute">
  /**
   * @var <xsl:choose>
          <xsl:when test="a:DataType='Identity'">string Identity</xsl:when>
		  <xsl:when test="a:DataType='Unique'">string Unique</xsl:when>
          <xsl:when test="a:DataType='I'">int </xsl:when>
          <xsl:when test="a:DataType='F'">float </xsl:when>
          <xsl:when test="a:DataType='BL'">bool </xsl:when>
          <xsl:when test="a:DataType='D'">date </xsl:when>
          <xsl:when test="a:DataType='DT'">datetime </xsl:when>
          <xsl:when test="contains(a:DataType,'TXT')">string </xsl:when>
          <xsl:when test="contains(a:DataType,'Text')">string </xsl:when>
        </xsl:choose><xsl:value-of select="a:Comment"></xsl:value-of><xsl:value-of select="a:Summary" />
   */
  public $<xsl:value-of select="a:Name"/>;
      </xsl:for-each>
  public function __construct(){
		$var=get_class_vars(__CLASS__);
    foreach(func_get_args() as $o){
      if(is_array($o)){
        foreach($o as $k => $v){<xsl:for-each select="c:Attributes/o:EntityAttribute[position()=1]">
            if($k=='<xsl:value-of select="a:Name"/>'){
              $this-><xsl:value-of select="a:Name"/>=<xsl:choose>
                <xsl:when test="a:DataType='Identity'">$v</xsl:when>
                <xsl:when test="a:DataType='Unique'">$v</xsl:when>
                <xsl:when test="a:DataType='I'">intval($v)</xsl:when>
                <xsl:when test="a:DataType='F'">floatval($v)</xsl:when>
                <xsl:when test="a:DataType='BL'">intval($v)>0?true:false</xsl:when>
                <xsl:when test="a:DataType='D'">intval($v)</xsl:when>
                <xsl:when test="a:DataType='DT'">intval($v)</xsl:when>
                <xsl:when test="contains(a:DataType,'TXT')">$v</xsl:when>
                <xsl:when test="contains(a:DataType,'Text')">$v</xsl:when>
              </xsl:choose>;
              }</xsl:for-each><xsl:for-each select="c:Attributes/o:EntityAttribute[position()>1]">
            else if($k=='<xsl:value-of select="a:Name"/>'){
                $this-><xsl:value-of select="a:Name"/>=<xsl:choose>
                  <xsl:when test="a:DataType='Identity'">$v</xsl:when>
                  <xsl:when test="a:DataType='Unique'">$v</xsl:when>
                  <xsl:when test="a:DataType='I'">intval($v)</xsl:when>
                  <xsl:when test="a:DataType='F'">floatval($v)</xsl:when>
                  <xsl:when test="a:DataType='BL'">intval($v)>0?true:false</xsl:when>
                  <xsl:when test="a:DataType='D'">intval($v)</xsl:when>
                  <xsl:when test="a:DataType='DT'">intval($v)</xsl:when>
                  <xsl:when test="contains(a:DataType,'TXT')">$v</xsl:when>
                  <xsl:when test="contains(a:DataType,'Text')">$v</xsl:when>
                </xsl:choose>;
            }</xsl:for-each>
        }
      }else if(is_object($o)){
        foreach($var as $k => $v){<xsl:for-each select="c:Attributes/o:EntityAttribute">
          if(isset($o-><xsl:value-of select="a:Name"/>)){
            $this-><xsl:value-of select="a:Name"/>=$o-><xsl:value-of select="a:Name"/>;
          }</xsl:for-each>
        }
      }
    }
  }

  public function __modetoarray(){
    $var=array();
    foreach(get_class_vars(__CLASS__) as $k => $v){
      $var[$k]=$this->$k;
    }
    return $var;
  }
}
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>